package com.yangfei.mystudy1020.activity;

import android.app.Activity;
import android.graphics.drawable.Animatable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.image.ImageInfo;
import com.yangfei.mystudy1020.R;
import com.yangfei.mystudy1020.utils.GlideCircleTransform;

import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation;

public class TestGlideActivity extends Activity {

    @BindView(R.id.fv_glide_load)
    ImageView mFvGlideLoad;

    String imgUrl = "http://store.if-chat.com:36000/cook/100534_1513132877_2177385200_1.ts?type=videogif&variety=short&w=240&h=426&rotate=0&format=webp";
    String imgWebp = "http://littlesvr.ca/apng/images/GenevaDrive.webp";
    String imgWebpLoss = "http://littlesvr.ca/apng/images/SteamEngine.webp";
    @BindView(R.id.fv_glide_load2)
    ImageView mFvGlideLoad2;
    @BindView(R.id.my_image_view)
    SimpleDraweeView mMyImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_glide);
        ButterKnife.bind(this);

//        mFvGlideLoad.setSize(1080,1920,10);

        RequestOptions requestOptions = new RequestOptions()
                .transforms(new BlurTransformation(15), new GlideCircleTransform(this))
                .dontAnimate();


        ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {
            @Override
            public void onFinalImageSet(
                    String id,
                    @Nullable ImageInfo imageInfo,
                    @Nullable Animatable anim) {
                Log.e("TestGlideActivity","onFinalImageSet");
                if (anim != null) {
                    // 其他控制逻辑
                    anim.start();
                }
            }
        };

        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(Uri.parse(imgWebpLoss))
                .setControllerListener(controllerListener)
                // 其他设置（如果有的话）
                .build();
        mMyImageView.setController(controller);

        Glide.with(this)
                .load(imgWebpLoss)
                .into(mFvGlideLoad2);

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }
}
